import React, { useEffect, useState, useContext } from "react";
import { Modal, Form, Input, Button, message } from "antd";
import { connect } from 'dva';
import { sampleContext } from "../index";
import { addSample } from "../../../service/sample";

const theProps = (state) => {
    return {
    }
}

function AddModal(props) {
    const { dispatch } = props;

    const AddInfo = useContext(sampleContext)

    const onFinish = async (value) => {
        const res = await addSample({
            info: value.info,
            region: value.region,
            size: 1,
            userId: localStorage.getItem('shale_sys_userid'),
            wellBlock: value.wellBlock,
            wellDeep: value.wellDeep,
            wellLayer: value.wellLayer,
            wellNum: value.wellNum,
            name: value.name
        })
        if (res.code == 200) {
            message.success('添加成功')
            dispatch({
                type: 'sample/getSample',
                payload: {
                    current: AddInfo.current,
                    limit: 5
                }
            })
            AddInfo.setVisible(false)
        } else {
            message.error('添加失败')
        }

    }
    return (
        <Modal
            title="上传"
            footer={[
            ]}
            visible={AddInfo.visible}
            onCancel={() => { AddInfo.setVisible(false) }}
        >
            <Form
                name="basic"
                // labelCol={{
                //     span: 8,
                // }}
                // wrapperCol={{
                //     span: 16,
                // }}
                initialValues={{
                    remember: true,
                }}
                onFinish={onFinish}
                // onFinishFailed={onFinishFailed}
                autoComplete="off"
            >
                <Form.Item
                    name="name"
                    label="样品名称"
                    rules={[
                        {
                            required: true,
                            message: '该字段不能为空',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    name="region"
                    label="区块"
                    rules={[
                        {
                            required: true,
                            message: '该字段不能为空',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    name="wellBlock"
                    label="井区"

                    rules={[
                        {
                            required: true,
                            message: '该字段不能为空',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>



                <Form.Item
                    name="wellDeep"
                    label="井深"

                    rules={[
                        {
                            required: true,
                            message: '该字段不能为空',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    name="wellLayer"
                    label="层位"

                    rules={[
                        {
                            required: true,
                            message: '该字段不能为空',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    name="wellNum"
                    label="井号"

                    rules={[
                        {
                            required: true,
                            message: '该字段不能为空',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    name="info"
                    label="样品性质"

                    rules={[
                        {
                            required: true,
                            message: '该字段不能为空',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item style={{ textAlign: 'right' }}>
                    <Button
                        type="primary" htmlType="submit">
                        确认
                    </Button>
                </Form.Item>
            </Form>
        </Modal>
    )
}
export default connect(theProps, null)(AddModal)